﻿using System.ComponentModel;
using System.Web.UI;
using System.Xml.Xsl;

namespace AgileDashboard.AppCode
{
    //borrowed from http://www.eggheadcafe.com/articles/20060603.asp

    [DefaultProperty("DocumentUrl")]
    [ToolboxData("<{0}:CustomXml1 runat=server></{0}:CustomXml1>")]
    public class CustomXml : System.Web.UI.WebControls.Xml
    {
        private string _documentUrl;

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string DocumentUrl
        {
            get
            {
                return _documentUrl;
            }

            set
            {
                _documentUrl = value;
                var xDoc = new System.Xml.XPath.XPathDocument(_documentUrl);
                XPathNavigator = xDoc.CreateNavigator();
            }
        }

        private string xslUrl;

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string XslUrl
        {
            get
            {
                return this.xslUrl;
            }

            set
            {
                this.xslUrl = value;
                var xslDoc = new System.Xml.XPath.XPathDocument(this.xslUrl);
                System.Xml.XPath.XPathNavigator xslNav = xslDoc.CreateNavigator();
                XslTransform xsltran = new XslTransform();
                xsltran.Load(xslNav);
                this.Transform = xsltran;
            }
        }
    }
}